import ParamsError from "../lib/errors/ParamsError";
namespace OrderUtil {
    /**
     * 类型非空数据检测
     * @param type 类型
     * @param data 数据
     * @param calcle 取消检查的字段数组
     * 
     */
    export function validataor(type: any, data: any, calcle: Array<string>) {
        for (const key in type) {
            if (typeof type[key] != typeof data[key]) {
                if (typeof type[key] == 'string' || typeof type[key] == 'number') {
                    throw new ParamsError(`类型异常${key}的类型 ${typeof data[key]}应该为${typeof type[key]}`)
                }
            }
            if ('number' == typeof type[key]) {
                if (calcle.includes(key)) { continue; }
                if (!(data[key]>0)) {
                    throw new ParamsError(`必填参数${key}`)
                }
            }
        }
    }
}

export default OrderUtil;